package org.xjtu.weteam.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xjtu.weteam.common.JsonResponse;
import org.xjtu.weteam.model.domain.Info;
import org.xjtu.weteam.model.dto.InfoDTO;
import org.xjtu.weteam.service.InfoService;


import java.util.List;

@RestController
@RequestMapping("/api/info")
public class InfoController {
    @Autowired
    private InfoService infoService;



    @PostMapping("/getInfo")
    @ResponseBody
    public JsonResponse getInfo(@RequestHeader("X-Access-Token") String token){
        List<Info> infos = infoService.selectInfoByUserId(token);
        return JsonResponse.success(infos);
    }
    @GetMapping("/deleteInfo")
    @ResponseBody
    public JsonResponse DeleteInfo(Integer id){
        //System.out.println("前端传值为："+id);
        return JsonResponse.success(infoService.removeInfoById(id));
    }
    @GetMapping ("/haveReadMessage")
    @ResponseBody
    public JsonResponse HaveReadMessage(Integer id){
        //System.out.println("前端传值为："+id);
        return JsonResponse.success(infoService.haveReadMessage(id));
    }
    @PostMapping("/sendMessage")
    @ResponseBody
    public JsonResponse sendMessage(InfoDTO info){
        return JsonResponse.success(infoService.sendMessage(info));
    }
}
